<template>
  <a-space>
    <span>{{ text }}</span>
    <a-button type="text" size="mini" @click="handleCopy">
      <template #icon>
        <icon-copy />
      </template>
    </a-button>
  </a-space>
</template>

<script setup lang="ts">
import { Message } from '@arco-design/web-vue'

defineOptions({ name: 'GiCellCopy' })

const props = defineProps<{
  text: string
}>()

const handleCopy = async () => {
  try {
    await navigator.clipboard.writeText(props.text)
    Message.success('复制成功')
  } catch (err) {
    Message.error('复制失败')
  }
}
</script>

<style scoped lang="scss">
:deep(.arco-btn-size-mini) {
  padding: 0 4px;
  height: 24px;
}
</style>
